import hannibal.util.Browser
import java.util.UUID

class SvnRepositoryTest extends GroovyTestCase
{
  Browser browser = new Browser()
  final urlRoot = "http://localhost:8080/svnservices/a/svnrepository"
  final static reposName = "someNewRepos" << UUID.randomUUID()

   void test_create_repository()
   {
		println("repository name is: " + reposName.toString());
		def response = browser.post(urlRoot, [name: reposName.toString()] )
		println("test_create_repository");
		println(response);
		assertTrue response.contains("Created")
  }

  void test_create_repository_if_already_exists()
  {
    browser.post(urlRoot, [name: reposName.toString()] )
    def response = browser.post(urlRoot, [name: reposName.toString()] )
    println("test_create_repository_if_already_exists");
	println(response);
    assertTrue response.contains("409")
  }

  void test_get_all_repositories()
  {
    def response = browser.get(urlRoot.toString())
    assertTrue  response.contains(reposName.toString())
  }

  void test_get_particular_existing_repository()
  {
    def urlRepos = urlRoot.toString() << '/'  << reposName.toString()
    def response = browser.get(urlRepos.toString())
    assertTrue response .contains(reposName.toString())
  }

  void test_get_particular_nonexisting_repository()
  {
    def urlRepos = urlRoot.toString() << '/'  << UUID.randomUUID()
    def response = browser.get(urlRepos.toString())
    assertTrue response.contains("Resource Not Found")
  }

  void test_delete_existing_repository()
  {
    def deletableReposName  = "deleteMe" << UUID.randomUUID()
    browser.post urlRoot, [name: deletableReposName.toString()]
    def response = browser.delete(urlRoot, [name: deletableReposName.toString()])
    assertTrue response.contains( "OK")
  }

  void test_delete_repository_with_bad_parameter_name()
  {
    def response = browser.delete(urlRoot,  [badParam: "someValue"])
    assertTrue response.contains("HannibalException")
  }
}